#pragma once

#include <string>
#include "Handles.h"
#include "AudioTypes.h"

namespace Audio
{
	class XMLAudioData
	///////////////////////////////////////////////////////////////////////////////
	// Description: Replaces categories
	//
	// Recent Changes:
	// -brasmuss 4/10/2007 : Created
	///////////////////////////////////////////////////////////////////////////////
	{
	public:
		XMLAudioData(std::string file, XMLFileHandle handle) : 
						m_uniqueVarHandle(1), m_uniqueGraphHandle(1), m_uniqueEventHandle(1),
						m_uniqueSubEventHandle(1), m_file(file), m_myHandle(handle) {}

		bool			LoadSoundXML(const char* file, class CoreSystem* core);
		bool			SaveSoundXML(const char* file);
		void			Clear();

		VariableHandle	UniqueVarHandle()      { return m_uniqueVarHandle++;		}
		GraphHandle		UniqueGraphHandle()    { return m_uniqueGraphHandle++;		}
		EventHandle		UniqueEventHandle()    { return m_uniqueEventHandle++;		}
		SubEventHandle  UniqueSubEventHandle() { return m_uniqueSubEventHandle++;	}
		//EffectHandle	UniqueEffectHandle()   { return m_uniqueEffectHandle++;		}

		VariableHandle	NewVariable(		const char* name, float min, float max );
		void			NewAudioFile(		const char* name, const char* file, FileHandle handle );
		GraphHandle		NewGraph(			const char* name );
		EventHandle		NewEvent(			const char* name, bool looping );


		Variable*		GetVariable(		const VariableHandle& handle );
		AudioFile*		GetAudioFile(		const FileHandle& handle );
		Graph*			GetGraph(			const GraphHandle& handle );
		EventData*		GetEventData(		const EventHandle& handle );

		VariableHandle	GetVariableHandle(	const char* name );
		VariableHandle	GetVariableHandle(	bool first );
		FileHandle		GetAudioFileHandle(	const char* name );
		FileHandle		GetAudioFileHandle(	bool first );
		GraphHandle		GetGraphHandle(		const char* name );
		GraphHandle		GetGraphHandle(		bool first );
		EventHandle		GetEventHandle(		const char* name );
		EventHandle		GetEventHandle(		bool first );
		SubEventHandle	GetSubEventHandle(	EventHandle eventID, bool first );
		EffectHandle	GetEffectHandle(	EventHandle eventID, SubEventHandle subID, bool first );

		bool			RemoveVariable(		const VariableHandle& handle );
		bool			RemoveGraph(		const GraphHandle& handle );
		bool			RemoveAudioFile(	const FileHandle& handle );
		bool			RemoveEventData(	const EventHandle& handle );

		// PUBLIC DATA
		std::string				m_file;
		std::string				m_path;

		graphmap_t				m_graphPool;			//!< Map of all the graphs
		variablemap_t			m_varPool;				//!< Map of all the variables
		eventdatamap_t			m_eventPool;			//!< Raw event data, NOT actual instantiations
		audiofilemap_t			m_audioFilePool;		//!< Map of audio files to be loaded
		handlemap_t				m_varHandles;			//!< Map of string/handle pairs
		handlemap_t				m_graphHandles;
		handlemap_t				m_eventHandles;
		handlemap_t				m_audioFileHandles;

	private:
		VariableHandle			m_uniqueVarHandle;		//!< Increments every time a variable is created
		GraphHandle				m_uniqueGraphHandle;	//!< Increments every time a graph is created
		EventHandle				m_uniqueEventHandle;
		SubEventHandle			m_uniqueSubEventHandle;
		//EffectHandle			m_uniqueEffectHandle;

		XMLFileHandle			m_myHandle;

		handlemap_t::iterator		m_curVarHandle;
		handlemap_t::iterator		m_curGraphHandle;
		handlemap_t::iterator		m_curEventHandle;
		handlemap_t::iterator		m_curAudioFileHandle;
		subeventdatamap_t::iterator m_curSubEventHandle;
		effectdatamap_t::iterator	m_curEffectHandle;

	};
}